// 抽签配置页面
Page({
  data: {
    title: '幸运抽签',
    totalCount: 10,
    winnerCount: 3,
    autoMode: false,
    enableNotification: false
  },

  // 修改标题
  onTitleInput(e) {
    this.setData({
      title: e.detail.value
    })
  },

  // 修改总人数
  onTotalCountInput(e) {
    const value = parseInt(e.detail.value) || 0;
    this.setData({
      totalCount: value,
      // 确保中奖人数不超过总人数
      winnerCount: Math.min(this.data.winnerCount, value)
    })
  },

  // 修改中奖人数
  onWinnerCountInput(e) {
    const value = parseInt(e.detail.value) || 0;
    // 确保中奖人数不超过总人数
    this.setData({
      winnerCount: Math.min(value, this.data.totalCount)
    })
  },

  // 切换自动抽签模式
  toggleAutoMode() {
    this.setData({
      autoMode: !this.data.autoMode
    })
  },

  // 切换开启提醒
  toggleNotification() {
    this.setData({
      enableNotification: !this.data.enableNotification
    })
  },

  // 跳转到参与页面
  navigateToJoin() {
    // 基本验证
    if (!this.data.title.trim()) {
      wx.showToast({
        title: '请输入活动标题',
        icon: 'none'
      });
      return;
    }

    if (this.data.totalCount <= 0) {
      wx.showToast({
        title: '参与人数必须大于0',
        icon: 'none'
      });
      return;
    }

    if (this.data.winnerCount <= 0) {
      wx.showToast({
        title: '中签人数必须大于0',
        icon: 'none'
      });
      return;
    }

    if (this.data.winnerCount > this.data.totalCount) {
      wx.showToast({
        title: '中签人数不能超过参与人数',
        icon: 'none'
      });
      return;
    }

    wx.navigateTo({
      url: '/pages/lucky-draw/join/index',
      success: (res) => {
        // 传递参数到下一个页面
        res.eventChannel.emit('acceptDrawParams', {
          title: this.data.title,
          totalCount: this.data.totalCount,
          winnerCount: this.data.winnerCount,
          autoMode: this.data.autoMode,
          enableNotification: this.data.enableNotification
        })
      }
    })
  },

  onLoad() {
    console.log('抽签配置页面加载成功')
  }
}) 